﻿using ESRI.ArcGIS.Display;
using System.Drawing;

public static class SymbolHelper
{
    // 获取污染颜色（所有污染物使用同一色带分级）
    public static IColor GetColorByPollutant(string type, double value)
    {
        Color color;

        switch (type.ToLower())
        {
            case "aqi":
                if (value <= 50) color = Color.Green;         // 优
                else if (value <= 100) color = Color.Yellow;   // 良
                else if (value <= 150) color = Color.Orange;   // 轻度污染
                else if (value <= 200) color = Color.Red;      // 中度污染
                else if (value <= 300) color = Color.Purple;  // 重度污染
                else color = Color.Maroon;                    // 严重污染
                break;
            case "pm25":
                // µg/m³
                if (value <= 15) color = Color.Green;         // 优
                else if (value <= 35) color = Color.Yellow;   // 良
                else if (value <= 55) color = Color.Orange;   // 轻度污染
                else if (value <= 75) color = Color.Red;      // 中度污染
                else if (value <= 115) color = Color.Purple;  // 重度污染
                else color = Color.Maroon;                    // 严重污染
                break;

            case "pm10":
                if (value <= 30) color = Color.Green;
                else if (value <= 50) color = Color.Yellow;
                else if (value <= 100) color = Color.Orange;
                else if (value <= 150) color = Color.Red;
                else if (value <= 250) color = Color.Purple;
                else color = Color.Maroon;
                break;

            case "no2":
                if (value <= 40) color = Color.Green;
                else if (value <= 80) color = Color.Yellow;
                else if (value <= 180) color = Color.Orange;
                else if (value <= 280) color = Color.Red;
                else if (value <= 400) color = Color.Purple;
                else color = Color.Maroon;
                break;

            case "so2":
                if (value <= 20) color = Color.Green;
                else if (value <= 50) color = Color.Yellow;
                else if (value <= 150) color = Color.Orange;
                else if (value <= 475) color = Color.Red;
                else if (value <= 800) color = Color.Purple;
                else color = Color.Maroon;
                break;

            case "co":
                if (value <= 1) color = Color.Green;
                else if (value <= 2) color = Color.Yellow;
                else if (value <= 5) color = Color.Orange;
                else if (value <= 10) color = Color.Red;
                else if (value <= 17) color = Color.Purple;
                else color = Color.Maroon;
                break;

            
            case "O3":
                if (value <= 100) color = Color.Green;
                else if (value <= 160) color = Color.Yellow;
                else if (value <= 200) color = Color.Orange;
                else if (value <= 300) color = Color.Red;
                else if (value <= 400) color = Color.Purple;
                else color = Color.Maroon;
                break;

            default:
                color = Color.Gray;
                break;
        }

        return ColorToRgbColor(color);
    }


    // 创建符号
    public static ISimpleMarkerSymbol CreatePollutionSymbol(double size, IColor color)
    {
        ISimpleMarkerSymbol symbol = new SimpleMarkerSymbolClass
        {
            Style = esriSimpleMarkerStyle.esriSMSCircle,
            Size = size,
            Color = color
        };
        return symbol;
    }

    // .NET Color → ArcGIS Color
    public static IRgbColor ColorToRgbColor(Color color)
    {
        return new RgbColorClass
        {
            Red = color.R,
            Green = color.G,
            Blue = color.B
        };
    }
}
